package D12_6z.反射andProperties_2;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Map;
import java.util.Properties;

public class Demo1 {
    public static void main(String[] args) throws Exception {
        run1();
        String string = run2();
        Class<?> aClass = Class.forName(string);
        Method run = aClass.getDeclaredMethod("run");
        Object o = aClass.newInstance();
        run.invoke(o,null);
    }
    public static void run1() throws Exception {
        Properties prop = new Properties();
        prop.setProperty("className","Y2019.M12_.D12_6z.反射andProperties_2.DemoClass");
        FileWriter wf = new FileWriter("class.properties");
        prop.store(wf,"xxx");
        wf.close();
    }
    public static String run2() throws IOException {
        Properties prop = new Properties();
        FileReader fr = new FileReader("class.properties");
        prop.load(fr);
        String name = "";
        for (Map.Entry<Object, Object> entry : prop.entrySet()) {
            name = (String) entry.getValue();
        }
        return name;
    }
}
